package com.dzt.androidframework.app;

import com.dzt.androidframework.R;
import com.dzt.androidframework.changeskin.lib.SkinManager;
import com.dzt.androidframework.database.dao.TaskDao;
import com.dzt.androidframework.database.tasks.TasksLocalDataSource;
import com.dzt.androidframework.exceptions.BaseExceptionHandler;
import com.dzt.androidframework.exceptions.LocalFileHandler;
import com.dzt.androidframework.utils.ActivityStackManager;
import com.dzt.androidframework.utils.AppResourceKit;
import com.dzt.androidframework.utils.JFileKit;
import com.dzt.androidframework.utils.JLogKit;
import com.dzt.androidframework.utils.JToastKit;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.lljjcoder.style.citylist.utils.CityListLoader;
import com.lljjcoder.style.citypickerview.CityPickerView;
import com.mob.mobapi.MobAPI;

import org.xutils.x;

import java.io.File;

public class LocalApplication extends BaseApplication {

	private static LocalApplication instance;
	public static ActivityStackManager sActivityStack;

	public static LocalApplication getInstance() {
		if (instance == null) {
			instance = new LocalApplication();
		}
		return instance;
	}

	@Override
	public void onCreate() {
		super.onCreate();
		instance = this;
		x.Ext.init(this);
		x.Ext.setDebug(true);
		JLogKit.getInstance().setTag("framework-->");
		// Create the APP crash log directory
		File appFolder = new File(JFileKit.getDiskCacheDir(this) + "/log/");
		JFileKit.createFolder(appFolder);
		ActivityStackManager.getInstance().init();
		JToastKit.getInstance().init(this);
		sActivityStack = ActivityStackManager.getInstance();
		//初始化换肤管理类
		SkinManager.getInstance().init(this);
		TasksLocalDataSource.getInstance().init();
		//Fresco初始化
		Fresco.initialize(this);
		AppResourceKit.getInstance().init(this);
		TaskDao.getInstance().init(this);
		MobAPI.initSDK(this, getString(R.string.mob_api_key));
		//选择其中一个即可，三个不必都写
		/**
		 * 预先加载仿iOS滚轮实现的全部数据
		 */
		CityPickerView.getInstance().init(this);

		/**
		 * 预先加载一级列表所有城市的数据
		 */
		CityListLoader.getInstance().loadCityData(this);

		/**
		 * 预先加载三级列表显示省市区的数据
		 */
		CityListLoader.getInstance().loadProData(this);
	}

	@Override
	public BaseExceptionHandler getDefaultUncaughtExceptionHandler() {
		return new LocalFileHandler(applicationContext);
	}
}
